{include file="public/user_header" /}

<ul class="nav nav-tabs nav-justified">
  <li role="presentation"><a href="home.html">产品溯源</a></li>
  <li role="presentation" class="active"><a href="company.html">企业查询</a></li>
</ul>

<div class="container" style=" height: 100%; width: 100%; padding: 10px 20%; margin-top: 30px; margin-bottom: 30px;">
  <form class="search-form" method="post">
    <div class="input-group" style="width: 100%;">
      <input type="text" id="gSellCode" name="search" class="form-control" placeholder="请输入企业名" autocomplete="off">

      <div class="input-group-btn">
        <button type="button"  onclick="btnSearch()" class="btn btn-warning btn-flat"><i class="fa fa-search"></i>
        </button>
      </div>
    </div>
    <!-- /.input-group -->
  </form>
</div>

<div class="container" style="text-align: center;display: none" id="notExist">
  <h3><i class="fa fa-warning text-yellow"></i> 无此商品</h3>
</div>
<div class="container" style="text-align: center; display: none;" id="exist">
  <div class="modal-content" style="width: 90%;">
    <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal" aria-label="Close">
        <span aria-hidden="true">×</span>
      </button>
      <h4 class="modal-title" id="myModalLabel">详情</h4>
    </div>
    <div class="modal-body" style="height: 100%;text-align: center;">
      <div class="form-group" style=" height: 36px;">
        <label for="firstname" style="height:34px; padding-top:1.2%;" class="col-sm-3 control-label">产品名称</label>
        <div class="col-sm-9">
          <input id="detail_gName" name="gName" class="form-control" readonly="readonly">
        </div>
      </div>
      <div class="form-group" style=" height: 36px;">
        <label for="firstname" style="height:34px; padding-top:1.2%;" class="col-sm-3 control-label">产品介绍</label>
        <div class="col-sm-9">
          <input id="detail_gIntroduce" name="gIntroduce" class="form-control" readonly="readonly">
        </div>
      </div>
      <div class="form-group" style=" height: 36px;">
        <label for="firstname" style="height:34px; padding-top:1.2%;" class="col-sm-3 control-label">产品认证</label>
        <div class="col-sm-9">
          <input id="detail_gAUT" name="gAUT" class="form-control" readonly="readonly">
        </div>
      </div>
      <div class="form-group" style=" height: 36px;">
        <label for="firstname" style="height:34px; padding-top:1.2%;" class="col-sm-3 control-label">证书编号</label>
        <div class="col-sm-9">
          <input id="detail_gAUTCode" name="gAUTCode" class="form-control" readonly="readonly">
        </div>
      </div>
      <div class="form-group" style=" height: 36px;">
        <label for="firstname" style="height:34px; padding-top:1.2%;" class="col-sm-3 control-label">产品类别</label>
        <div class="col-sm-9">
          <input id="detail_gClass" name="gClass" class="form-control" readonly="readonly">
        </div>
      </div>
      <div class="form-group" style=" height: 36px;">
        <label for="firstname" style="height:34px; padding-top:1.2%;" class="col-sm-3 control-label">产地环境</label>
        <div class="col-sm-9">
          <input id="detail_gENV" name="gENV" class="form-control" readonly="readonly">
        </div>
      </div>
      <div class="form-group" style=" height: 36px;">
        <label for="firstname" style="height:34px; padding-top:1.2%;" class="col-sm-3 control-label">产品销售码</label>
        <div class="col-sm-9">
          <input id="detail_gSellCode" name="gSellCode" class="form-control" readonly="readonly">
        </div>
      </div>
    </div>
  </div>
</div>

</div>


<!-- 引入js依赖 -->
{include file="public/introduce" /}

<script>
  function btnSearch(){

    //获取输入值
    var gSellCode = $('#gSellCode').val();

    var div1 = document.getElementById('notExist')
    var div2 = document.getElementById('exist')
    //初始都不显示
    div1.setAttribute('style','text-align: center;display: none');
    div2.setAttribute('style','text-align: center;display: none');

    //正则判断输入是否合法
    var strRegex = "[a-zA-Z0-9]"
    var ze = new RegExp(strRegex);
    if( gSellCode=="" || gSellCode==" "){
      ;//什么也不做
    }else if(!ze.test(gSellCode)){
      alert("输入格式错误")
    }else{
      var result = $.ajax({
        url: "../user/searchByCode",
        type: "post",
        async: false,
        data: {
          gSellCode : gSellCode
        }
      }).responseJSON;

      if(result == "null"){
        div1.setAttribute('style','text-align: center;');
      }else{
        $('#detail_gName').val(result['gName']);
        $('#detail_gIntroduce').val(result['gIntroduce']);
        $('#detail_gAUT').val(result['gAUT']);
        $('#detail_gAUTCode').val(result['gAUTCode']);
        $('#detail_gClass').val(result['gClass']);
        $('#detail_gENV').val(result['gENV']);
        $('#detail_gSellCode').val(result['gSellCode']);
        div2.setAttribute('style','text-align: center;');
      }
    }


  }
</script>

</body>

</html>